package com.lwt.hospital.controller;

import com.lwt.hospital.model.Appointment;
import com.lwt.hospital.model.Doctor;
import com.lwt.hospital.model.Hospitalized;
import com.lwt.hospital.model.Question;
import com.lwt.hospital.service.DoctorService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.print.Doc;
import javax.servlet.http.HttpSession;

/**
 * @author 丁兆顺
 * @date 2020/5/19 21:05
 * @desciption
 */
@RestController
public class DoctorController extends BaseController {

    @Resource
    private DoctorService doctorService;

    @RequestMapping("/changePassword")
    public String changePassword(@RequestBody Doctor doctor, HttpSession session){
        int result = doctorService.changePassword(doctor, session);
        System.out.println(doctor.getOldPassword()+"   " +doctor.getPassword());
        if(result > 0){
            session.removeAttribute("userInfo");
            return getCommonSUCESS("修改成功，请重新登录！");
        }else if(result == -1){
            return getCommonERROR("修改失败！旧密码输入错误！");
        }else{
            return getCommonERROR("修改失败！");
        }
    }

    @RequestMapping("/getPatient")
    public String getPatient(HttpSession session){
        return getCommonSUCESS(doctorService.getPatient(session));
    }

    @RequestMapping("/outHospital")
    public String outHospital(@RequestBody Hospitalized hospitalized){
        System.out.println(hospitalized.getId());
        int result = doctorService.outHospital(hospitalized.getId());
        if(result > 0){
            return getCommonSUCESS("修改成功！");
        }else{
            return getCommonERROR("修改失败");
        }
    }


    @RequestMapping("/getAppointment")
    public String getAppointment(HttpSession session){
        return getCommonSUCESS(doctorService.getAppointment(session));
    }

    @RequestMapping("/getAAppointment")
    public String getAAppointment(@RequestBody Appointment appointment,HttpSession session){
        return getCommonSUCESS(doctorService.getAAppointment(appointment,session));
    }


    @RequestMapping("/modifyAppointment")
    public String modifyAppointment(@RequestBody Appointment appointment,HttpSession session){
        System.out.println(appointment);
        int result = doctorService.modifyAppointment(appointment, session);
        if(result > 0){
            return getCommonSUCESS("处理完毕！");
        }else{
            return getCommonERROR("出现失败！");
        }
    }

    @RequestMapping("/getQuestion")
    public String getQuestion(HttpSession session){
        return getCommonSUCESS(doctorService.getQuestion(session));
    }

    @RequestMapping("/getAQuestion")
    public String getAQuestion(@RequestBody Question question,HttpSession session){
        return getCommonSUCESS(doctorService.getAQuestion(question,session));
    }

    @RequestMapping("/updateQuestion")
    public String updateQuestion(@RequestBody Question question,HttpSession session){
        int result = doctorService.updateQuestion(question, session);
        if(result > 0){
            return getCommonSUCESS("操作成功！");
        }else{
            return getCommonERROR("操作失败！");
        }
    }


    @RequestMapping("/getDoctor")
    public String getDoctor(){
        return getCommonSUCESS(doctorService.selectAllDoc());
    }

    @RequestMapping("/delDoc")
    public String delDoc(@RequestBody Doctor doctor,HttpSession session){
        int result = doctorService.delDoc(doctor, session);
        if(result > 0){
            return getCommonSUCESS("操作成功！");
        }else{
            return getCommonERROR("操作失败！");
        }
    }

    @RequestMapping("/addDoctor")
    public String addDoctor(@RequestBody Doctor doctor ,HttpSession session){
        int result = doctorService.addDoc(doctor, session);
        if(result > 0){
            return getCommonSUCESS("添加成功!");
        }else{
            return getCommonERROR("添加失败！");
        }
    }

    @RequestMapping("/selectADoc")
    public String selectADoc(@RequestBody Doctor doctor){
        System.out.println(doctor.getId());
        return getCommonSUCESS(doctorService.selectDocById(doctor));
    }

    @RequestMapping("/updateDoc")
    public String updateDoc(@RequestBody Doctor doctor,HttpSession session){
        int result = doctorService.updateDoc(doctor);
        if(result > 0){
            return getCommonSUCESS("修改成功！");
        }else{
            return getCommonERROR("修改失败!");
        }
    }

}
